#-------------------------------------------------------------------------
#
# Makefile for backend/catalog
#
# src/backend/catalog/Makefile
#
#-------------------------------------------------------------------------

subdir = src/backend/catalog
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global

ifndef ADDON_DIR
QUICKLZ_COMPRESSION = quicklz_compression.o
endif

OBJS = catalog.o dependency.o heap.o index.o indexing.o namespace.o aclchk.o \
       pg_aggregate.o pg_constraint.o pg_conversion.o pg_depend.o \
       pg_largeobject.o pg_namespace.o pg_operator.o pg_proc.o pg_shdepend.o \
       pg_type.o toasting.o \
       pg_exttable.o pg_extprotocol.o \
       pg_proc_callback.o \
       aoseg.o aoblkdir.o gp_fastsequence.o \
       pg_attribute_encoding.o pg_compression.o aovisimap.o \
       gp_global_sequence.o gp_persistent.o pg_appendonly.o \
       aocatalog.o hiddencat.o $(QUICKLZ_COMPRESSION)


SUBDIRS = caql core

BKIFILES = postgres.bki postgres.description postgres.shdescription

include $(top_srcdir)/src/backend/common.mk

all: gp_toolkit.sql gp_toolkit_test.sql $(BKIFILES)

JETPACK_NAME = toolkit
JETPACK_SCHEMA = gp_$(JETPACK_NAME)
JETPACK_OBJECT_PREFIX = gp_
JETPACK_PREFIX = $(JETPACK_SCHEMA).$(JETPACK_OBJECT_PREFIX)
JETPACK_PREFIX_AUX = $(JETPACK_SCHEMA).__$(JETPACK_OBJECT_PREFIX)
AO_CO_DIAGNOSTICS_PATHNAME = $$libdir\/gp_ao_co_diagnostics
WORKFILE_PATHNAME = $$libdir\/gp_workfile_mgr
SESSION_STATE_PATHNAME = $$libdir\/gp_session_state

gp_toolkit.sql: gp_toolkit.sql.in
	sed \
	-e 's/%%JETPACK_NAME%%/$(JETPACK_NAME)/g' \
	-e 's/%%JETPACK_SCHEMA%%/$(JETPACK_SCHEMA)/g' \
	-e 's/%%JETPACK_PREFIX%%/$(JETPACK_PREFIX)/g' \
	-e 's/%%JETPACK_OBJECT_PREFIX%%/$(JETPACK_OBJECT_PREFIX)/g' \
	-e 's/%%JETPACK_PREFIX_AUX%%/$(JETPACK_PREFIX_AUX)/g' \
	-e 's/%%AO_CO_DIAGNOSTICS_MODULE%%/$(AO_CO_DIAGNOSTICS_PATHNAME)/g' \
	-e 's/%%WORKFILE_MODULE%%/$(WORKFILE_PATHNAME)/g' \
	-e 's/%%SESSION_STATE_MODULE%%/$(SESSION_STATE_PATHNAME)/g' \
	-e 's/	/    /g' \
	$< > $@

gp_toolkit_test.sql: gp_toolkit_test.sql.in
	sed \
	-e 's/%%JETPACK_NAME%%/$(JETPACK_NAME)/g' \
	-e 's/%%JETPACK_SCHEMA%%/$(JETPACK_SCHEMA)/g' \
	-e 's/%%JETPACK_PREFIX%%/$(JETPACK_PREFIX)/g' \
	-e 's/%%JETPACK_PREFIX_AUX%%/$(JETPACK_PREFIX_AUX)/g' \
	-e 's/%%AO_CO_DIAGNOSTICS_MODULE%%/$(AO_CO_DIAGNOSTICS_PATHNAME)/g' \
	-e 's/	/    /g' \
	$< > $@

# TIDYCAT_BEGIN_CODEGEN
# WARNING: DO NOT MODIFY THE FOLLOWING SECTION:
# Generated by ./tidycat.pl version 31
# on Thu Sep  1 16:43:17 2011


TIDYCAT_BKI_SRCS := \
	pg_attribute_encoding.h \
	pg_auth_time_constraint.h \
	pg_compression.h \
	pg_foreign_data_wrapper.h \
	pg_foreign_server.h \
	pg_foreign_table.h \
	pg_proc_callback.h \
	pg_partition_encoding.h \
	pg_type_encoding.h

# TIDYCAT_END_CODEGEN

# Note: there are some undocumented dependencies on the ordering in which
# the catalog header files are assembled into postgres.bki.  In particular,
# indexing.h had better be last, and toasting.h just before it.

POSTGRES_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/,\
	pg_proc.h pg_type.h pg_attribute.h pg_class.h pg_autovacuum.h \
	pg_attrdef.h pg_constraint.h pg_inherits.h pg_index.h \
	pg_operator.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \
	pg_language.h pg_largeobject.h pg_aggregate.h pg_statistic.h \
	pg_rewrite.h pg_trigger.h pg_listener.h pg_description.h pg_cast.h \
	pg_namespace.h pg_conversion.h pg_depend.h \
	pg_database.h pg_tablespace.h pg_pltemplate.h \
	pg_authid.h pg_auth_members.h pg_shdepend.h pg_shdescription.h pg_resqueue.h \
	gp_configuration.h gp_id.h gp_policy.h gp_version.h \
	gp_segment_config.h gp_san_config.h \
	gp_verification_history.h \
	pg_window.h \
	pg_exttable.h pg_appendonly.h pg_appendonly_alter_column.h aoseg.h \
	gp_fastsequence.h pg_extprotocol.h \
	pg_partition.h pg_partition_rule.h pg_filespace.h pg_filespace_entry.h \
	gp_global_sequence.h gp_persistent.h \
	$(TIDYCAT_BKI_SRCS) \
	pg_user_mapping.h toasting.h indexing.h \
    )

pg_includes = $(sort -I$(top_srcdir)/src/include -I$(top_builddir)/src/include)

# see explanation in ../parser/Makefile
postgres.description: postgres.bki ;

postgres.shdescription: postgres.bki ;

postgres.bki: genbki.sh $(POSTGRES_BKI_SRCS) \
    $(top_srcdir)/src/include/postgres_ext.h $(top_builddir)/src/include/pg_config_manual.h
	AWK='$(AWK)' $(SHELL) $< $(pg_includes) --set-version=$(VERSION) -o postgres $(POSTGRES_BKI_SRCS)

.PHONY: install-data
install-data: $(BKIFILES) installdirs
	$(INSTALL_DATA) $(call vpathsearch,postgres.bki) '$(DESTDIR)$(datadir)/postgres.bki'
	$(INSTALL_DATA) $(call vpathsearch,postgres.description) '$(DESTDIR)$(datadir)/postgres.description'
	$(INSTALL_DATA) $(call vpathsearch,postgres.shdescription) '$(DESTDIR)$(datadir)/postgres.shdescription'
	$(INSTALL_DATA) $(srcdir)/system_views.sql '$(DESTDIR)$(datadir)/system_views.sql'
	$(INSTALL_DATA) $(srcdir)/information_schema.sql '$(DESTDIR)$(datadir)/information_schema.sql'
	$(INSTALL_DATA) $(call vpathsearch,cdb_util.sql) '$(DESTDIR)$(datadir)/cdb_util.sql'
	$(INSTALL_DATA) $(call vpathsearch,cdb_schema.sql) '$(DESTDIR)$(datadir)/cdb_init.d/cdb_schema.sql'
	$(INSTALL_DATA) $(srcdir)/sql_features.txt '$(DESTDIR)$(datadir)/sql_features.txt'
	$(INSTALL_DATA) $(call vpathsearch,gp_toolkit.sql) '$(DESTDIR)$(datadir)/gp_toolkit.sql'
	$(INSTALL_DATA) $(call vpathsearch,compaction_info.sql) '$(DESTDIR)$(datadir)/compaction_info.sql'

installdirs:
	$(MKDIR_P) '$(DESTDIR)$(datadir)'

.PHONY: uninstall-data
uninstall-data:
	rm -f $(addprefix '$(DESTDIR)$(datadir)'/, $(BKIFILES) system_views.sql information_schema.sql cdb_init.d/cdb_schema.sql sql_features.txt)

clean:
	rm -f SUBSYS.o $(OBJS) $(BKIFILES) gp_toolkit_test.sql gp_toolkit.sql
